def recurringSeqLength(n):
    """ Finds the length of a recurring sequence in the decimal expansion of 1/n"""
    remainders = []
    remainder = 1
    
    while True:   
        remainders.append(remainder)
        
        if n < remainder:
            digit = remainder / n
        else:
            digit = 0
            
        remainder -= digit * n        
        if remainder == 0: return 0         # exact result, no cycles

        remainder *= 10
        
        if remainder in remainders:         # found cycle
            return len(remainders) - remainders.index(remainder)

print max((recurringSeqLength(i), i) for i in xrange(2, 1001))
